package main

import (
	"log"
	"time"

	"golang.org/x/net/context"
	"google.golang.org/grpc"
	pb "helloworld/proto"
)

const (
	defaultName = "world"
)

func main() {
	conn, err := grpc.Dial("localhost:50051",grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v",err)
	}

	defer conn.Close()

	c := pb.NewGreeterClient(conn)

	ctx, cancel := context.WithTimeout(context.Background(),time.Second)

	defer cancel()

	r, err := c.SayHello(ctx,&pb.HelloRequest{Name:"world"})
	if err != nil {
		log.Fatalf("could not greet: %v",err)
	}

	log.Printf("Greeting: %s", r.Message)
}
